package com.eslserver.core;

import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class Config {
	public static final Logger log = LoggerFactory.getLogger(Config.class);

	private Document doc;

	public Config(InputStream is) {
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

		if (is == null) {
			// is should never be null or else the config doc won't build...
		}

		DocumentBuilder db;
		try {
			db = dbf.newDocumentBuilder();

			try {
				doc = db.parse(is);
			} finally {
				is.close();
			}
		} catch (SAXException e) {
			log.error(e.getMessage());
		} catch (IOException e) {
			log.error(e.getMessage());
		} catch (ParserConfigurationException e) {
			log.error(e.getMessage());
		}
	}

	public Document getDoc() {
		return doc;
	}
}
